package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mappers.SettingsMapper;
import com.tanhua.model.domain.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author: cl
 * @Date: 2022/5/2 - 05 - 02
 * @Description:
 */

/**
 * 通用设置服务
 */
@DubboService
public class SettingsApiImpl implements SettingsApi {

    @Autowired
    private SettingsMapper settingsMapper;

    /**
     * 根据用户id查询设置信息
     *
     * @param userId
     * @return
     */
    @Override
    public Settings findByUserId(Long userId) {

        Settings settings = settingsMapper.selectOne(
                Wrappers.<Settings>lambdaQuery()
                        .eq(Settings::getUserId, userId)
        );
        return settings;
    }

    /**
     * 新增设置信息
     *
     * @param settings2
     */
    @Override
    public void save(Settings settings2) {

        settingsMapper.insert(settings2);
    }

    /**
     * 修改设置信息
     *
     * @param settings1
     */
    @Override
    public void update(Settings settings1) {

        settingsMapper.updateById(settings1);
    }
}
